package com.example.myapplication.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.myapplication.R;

/**
 * 用来接收数据的Activity案例
 *
 * @author Yuansir
 * @version V1.0
 * @since 2025/7/30 11:33
 */
public class ReceiveDataActivity extends AppCompatActivity {

    private TextView textView;
    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_receive_date);
        // ----------------------------------------------------------
        textView = findViewById(R.id.tv_message);
        // 取得传入的数据
        String msg = getIntent().getStringExtra("message");
        // 设置到UI上显示
        textView.setText(msg);
        // ----------------------------------------------------------
        button = findViewById(R.id.btn_back);
        // 关闭当前Activity, 回传数据回去
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 设置回传信息
                Intent dataIntent = new Intent();
                dataIntent.putExtra("aaa", "123123123123123");
                setResult(119, dataIntent);
                // 结果当前Acitivyt
                finish();
            }
        });
    }
}